package de.g18.llmaa.gui.workspace.internalFrame.product;

import java.util.ArrayList;
import java.util.HashMap;

import javax.swing.JComponent;

import de.g18.llmaa.logic.vos.VOProduct_Key;

/**
 * Das Model eines Produkt Fensters. Dieses Model beinahltet das anzuzeigende
 * Produkt und alle aktuell sichtbaren Schlüssel.
 * 
 * @author Gruppe LLMAA
 * 
 */
public class InternalFrame_Product_Model implements
		IInternalFrame_Product_Model {

	private VOProduct_Key key;

	private ArrayList<IFrame_Product_Beobachter> list_Beobachters;
	private HashMap<String, JComponent> map_VisibleElements;

	public InternalFrame_Product_Model(VOProduct_Key key) {
		this.key = key;
		list_Beobachters = new ArrayList<IFrame_Product_Beobachter>();
		map_VisibleElements = new HashMap<String, JComponent>();
	}

	public void registerBeobachter(IFrame_Product_Beobachter beobachter) {
		list_Beobachters.add(beobachter);

	}

	public VOProduct_Key getKey() {
		return key;
	}

	@Override
	public HashMap<String, JComponent> getVisibleElements() {

		return map_VisibleElements;
	}

	public void addVisibleElement(String title, JComponent compoent) {
		try {
			JComponent erg = map_VisibleElements.get(title);
			erg.updateUI();
		} catch (Exception e) {
			map_VisibleElements.put(title, compoent);
			akutalisiereBeobachter();
		}

	}

	private void akutalisiereBeobachter() {
		for (IFrame_Product_Beobachter beobachter : list_Beobachters) {
			beobachter.aktualisiere(this);
		}

	}

}
